<template>
  <div class="custom-table-container">
    <el-row :gutter="20">
      <el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="12">
        <el-card class="access" shadow="hover" skeleton>
          <div class="card-header" slot="header">
            <div>
              <vab-icon icon="line-chart-line" />
              料架信息
            </div>
          </div>
          <el-table :data="list1" style="width: 100%">
            <el-table-column
              align="center"
              label="序号"
              show-overflow-tooltip
              width="200"
            >
              <template #default="{ $index }">
                {{ $index + 1 }}
              </template>
            </el-table-column>
            <el-table-column prop="Id" label="料架编号"></el-table-column>
            <el-table-column prop="Name" label="料架名称"></el-table-column>
            <el-table-column prop="RowCount" label="行数"></el-table-column>
            <el-table-column prop="ColumnCount" label="列数"></el-table-column>
            <el-table-column prop="Type" label="型号"></el-table-column>
            <template slot="empty">
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
          <el-pagination
            background
            :current-page="queryForm1.pageNo"
            :layout="layout"
            :page-size="queryForm1.pageSize"
            :total="total1"
            @current-change="handleCurrentChange1"
            @size-change="handleSizeChange1"
          />
        </el-card>
      </el-col>
      <el-col :lg="12" :md="12" :sm="12" :xl="12" :xs="12">
        <el-card class="access" shadow="hover" skeleton>
          <div class="card-header" slot="header">
            <div>
              <vab-icon icon="line-chart-line" />
              库存信息
            </div>
          </div>
          <el-table :data="list2" style="width: 100%">
            <el-table-column align="center" label="序号" show-overflow-tooltip>
              <template #default="{ $index }">
                {{ $index + 1 }}
              </template>
            </el-table-column>
            <el-table-column
              prop="WarehouseId"
              label="料架编号"
            ></el-table-column>
            <el-table-column prop="Id" label="库位"></el-table-column>
            <el-table-column prop="State" label="料库状态">
              <template slot-scope="scope">
                <template v-if="scope.row.State == '空闲'">
                  <el-tag type="success">空闲</el-tag>
                </template>
                <template v-else>
                  <el-tag type="danger">占用</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="TrayId" label="托盘编号"></el-table-column>
            <el-table-column prop="PartId" label="零件编号"></el-table-column>
            <el-table-column prop="MaterialState" label="物料状态">
              <template slot-scope="scope">
                <template v-if="scope.row.MaterialState == '未加工'">
                  <el-tag>未加工</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '加工状态异常'">
                  <el-tag type="warning">加工状态异常</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '待加工'">
                  <el-tag type="info">待加工</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '加工中'">
                  <el-tag type="info">加工中</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '加工完成'">
                  <el-tag type="success">加工完成</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '加工出错'">
                  <el-tag type="danger">加工出错</el-tag>
                </template>
                <template v-else-if="scope.row.MaterialState == '信息异常'">
                  <el-tag type="warning">信息异常</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="QualityState" label="检测状态">
              <template slot-scope="scope">
                <template v-if="scope.row.QualityState == '合格'">
                  <el-tag type="success">合格</el-tag>
                </template>
                <template v-else-if="scope.row.QualityState == '不合格'">
                  <el-tag type="danger">不合格</el-tag>
                </template>
                <template v-else-if="scope.row.QualityState == '待检测'">
                  <el-tag type="warning">待检测</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button size="small" type="text" @click="caozuo(scope.row)">
                  零件检测状态
                </el-button>
              </template>
            </el-table-column>
            <template slot="empty">
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
          <el-pagination
            background
            :current-page="queryForm2.pageNo"
            :layout="layout"
            :page-size="queryForm2.pageSize"
            :total="total2"
            @current-change="handleCurrentChange2"
            @size-change="handleSizeChange2"
          />
        </el-card>
      </el-col>
    </el-row>
    <el-dialog
      :close-on-click-modal="false"
      :visible="showDialog"
      width="500px"
      title="零件检测状态"
      :before-close="handleClose2"
    >
      <div>
        <el-select v-model="statuvalue" placeholder="请选择零件检测状态">
          <el-option
            v-for="item in statuoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <template slot="footer">
        <span class="dialog-footer">
          <el-button @click="showDialog = false">取消</el-button>
          <el-button @click="gdconfirm" type="primary">确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  import {
    WarehouseManager,
    InventoryInfo,
    SetMaterialQualityResult,
  } from '@/api/material'
  export default {
    data() {
      return {
        statuvalue: '',
        statuoptions: [
          {
            label: '合格',
            value: '合格',
          },
          {
            label: '不合格',
            value: '不合格',
          },
          // {
          //   label: '报废',
          //   value: '报废',
          // },
        ],
        showDialog: false,
        list1: [],
        total1: 0,
        list2: [],
        total2: 0,

        layout: 'total, sizes, prev, pager, next, jumper',
        queryForm1: {
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
        queryForm2: {
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
        currow: {},
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      handleClose2() {
        this.showDialog = false
      },
      caozuo(row) {
        this.currow = row
        this.showDialog = true
      },
      handleSizeChange1(val) {
        this.queryForm1.pageSize = val
        this.getData1()
      },
      handleCurrentChange1(val) {
        this.queryForm1.pageNo = val
        this.getData1()
      },
      handleSizeChange2(val) {
        this.queryForm2.pageSize = val
        this.getData2()
      },
      handleCurrentChange2(val) {
        this.queryForm2.pageNo = val
        this.getData2()
      },
      gdconfirm() {
        console.log('currow', this.currow)
        SetMaterialQualityResult({
          MaterialId: this.currow.PartId,
          Result: this.statuvalue,
        }).then((res) => {
          this.showDialog = false
          this.fetchData()
        })
      },
      getData1() {
        const params = {
          Index: this.getPage(this.queryForm1.pageNo, this.queryForm1.pageSize),
          Count: this.queryForm1.pageSize,
        }
        WarehouseManager(params).then((res) => {
          this.list1 = res.WarehouseInfo
          this.total1 = res.TotalCount
        })
      },
      getData2() {
        const params = {
          Index: this.getPage(this.queryForm2.pageNo, this.queryForm2.pageSize),
          Count: this.queryForm2.pageSize,
        }
        InventoryInfo(params).then((res) => {
          this.list2 = res.InventoryInfo
          this.total2 = res.TotalCount
        })
      },
      fetchData() {
        this.getData1()
        this.getData2()
      },
    },
  }
</script>

<style lang="scss" scoped>
  $base: '.custom-table';
  #{$base}-container {
    padding: 0 !important;
    background: $base-color-background !important;

    #{$base}-user-info {
      padding: $base-padding;
      text-align: center;

      :deep() {
        .el-avatar {
          img {
            cursor: pointer;
          }
        }
      }

      &-full-name {
        margin-top: 15px;
        font-size: 24px;
        font-weight: 500;
        color: #262626;
      }

      &-description {
        margin-top: 8px;
      }

      &-follow {
        margin-top: 15px;
      }

      &-list {
        margin-top: 18px;
        line-height: 30px;
        text-align: left;
        list-style: none;

        h5 {
          margin: -20px 0 5px 0;
        }

        :deep() {
          .el-tag {
            margin-right: 10px !important;
          }

          .el-tag + .el-tag {
            margin-left: 0;
          }
        }
      }
    }

    #{$base}-item {
      display: flex;

      i {
        font-size: 40px;
      }

      &-content {
        box-sizing: border-box;
        flex: 1;
        margin-left: $base-margin;

        &-second {
          margin-top: 8px;
        }
      }
    }
  }
</style>
